#!/usr/bin/env python -u
# -*- coding: utf-8 -*-
import conf
import pynotify
from utils import *

try:
    import pygtk
    pygtk.require("2.0")
    import gtk
    import gtk.glade    
except ImportError,cause:
    sys.stderr.write("ImportError: Module is not present %s" % cause)
    exit(-1)
 
class SystemIcon:
    def __init__(self,parent):
        self.parent = parent
        self.icon = gtk.status_icon_new_from_stock(gtk.STOCK_ABOUT)
        self.icon.connect("popup-menu",self.on_right_click)
        self.icon.connect("activate",self.parent.show_hide_window)
        pynotify.init("twicage")

    def alert(self,title,text):
        self.notification = pynotify.Notification("Title", "body", "dialog-warning")
        self.notification.set_urgency(pynotify.URGENCY_LOW)
        self.notification.set_timeout(pynotify.EXPIRES_DEFAULT)
        self.notification.show()

    def on_right_click(self,icon,event_button,event_time):
        menu = gtk.Menu()
        item = gtk.MenuItem("Sair")
        item.show()
        menu.append(item)
        menu.popup(None, None,
            gtk.status_icon_position_menu, event_button,
            event_time, icon)
        
        # show the application hiddem
        item.connect("activate",self.parent.exit_app)
